<template>
  <contentModel title="详情" :has-footer="false" @close="cancel" @open="open">
    <standard-table
      ref="detailTable"
      v-model:selectedKeys="detailSelectedKeys"
      :component-config="tableComponentConfig"
      :render-config="tableRenderConfig"
      :render-keys="detailTableRenderKeys"
      :loading="detailTableLoading"
      :data="detailTableData"
      :total="detailTableTotal"
      @page-change="detailPageChange"
      @page-size-change="detailPageSizeChange"
    >
    </standard-table>
  </contentModel>
</template>

<script lang="ts" setup>
  import { defineAsyncComponent, ref, toRefs } from 'vue';
  import { getPmsDcdItemDetailPage } from '@/api/purchaseArrival/goodsInformationUpload';
  import StandardTable from '@/common/components/standard-table/index.vue';
  import {
    tableRenderConfig,
    tableComponentConfig,
  } from '../moduleCommon/tableComp/baseTableConfig';

  const props = defineProps({
    modelValue: {
      type: Boolean,
      default: false,
    },
    // eslint-disable-next-line vue/require-prop-types
    selectId: {
      default: null,
    },
  });
  const contentModel = defineAsyncComponent(
    () => import('@/common/components/content-model/index.vue')
  );
  const emits = defineEmits(['update:modelValue']);
  const cancel = () => {
    emits('update:modelValue', false);
  };
  const { selectId } = toRefs(props);
  // const { cancel } = useModelFun();
  // const loading = ref(false);

  const detailTableRenderKeys = [
    'fileCode',
    'unitCode',
    'unitState',
    'fullname',
    'locaname',
    'shortname',
  ];
  const open = () => {
    if (detailTableLoading.value) return;
    if (selectId?.value) {
      detailTableLoading.value = true;
      getDetailTableList();
    } else {
      detailTableLoading.value = false;
    }
  };
  // table-list
  const detailTable = ref(null);
  // const detailRenderKeys = ['orderNo', 'mdsItemCode'];
  const detailSelectedKeys = ref([]);
  // let detailSelectRowList: Array<any> = [];
  const detailTableLoading = ref(false);
  const detailTableData = ref([]);
  const detailTableTotal = ref(0);
  // const selectDetailId = ref<string | number | null>(null);
  // const searchHandle = (query = {}) => {
  //   getDetailTableList(query);
  // };
  // const resetHandle = () => {
  //   getDetailTableList({});
  // };
  const detailPageChange = () => {
    getDetailTableList();
  };
  const detailPageSizeChange = () => {
    getDetailTableList();
  };
  const getDetailTableList = async (query = {}) => {
    const page = detailTable.value.getStatus();
    detailTableLoading.value = true;
    const { data } = await getPmsDcdItemDetailPage({
      ...query,
      ...page,
      unitCode: selectId.value,
    });
    detailTableData.value = data.list;
    detailTableTotal.value = data.total;
    detailTableLoading.value = false;
  };
  const init = () => {};
  init();
</script>
